// pages/evaluation/index.js
import {
  ApiOrderUserComment,
  ApiorderDoctorComment
} from '../api/index'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    autosize: {
      maxHeight: 500,
      minHeight: 200
    },
    opt: {
      order_id: '',
      content: '',
    },
    activea: false,
    activeb: false,
    activec: false,
    actived: false,
    activee: false,
    activef: false,
    activeArr: [{
      label: 'activea',
      value: false,
      name: '沟通畅快',
      id: '0'
    }, {
      label: 'activeb',
      value: false,
      name: '表述清楚',
      id: '1'
    }, {
      label: 'activec',
      value: false,
      name: '态度好',
      id: '2'
    }, {
      label: 'actived',
      value: false,
      name: '确认快',
      id: '3'
    }, {
      label: 'activee',
      value: false,
      name: '表达精准',
      id: '4'
    }, {
      label: 'activef',
      value: false,
      name: '反馈积极',
      id: '5'
    }]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options)
    let val = JSON.parse(options.id)
    this.setData({
      'opt.order_id': val.id,
      dataList: val
    })

  },
  onChange(e) {
    const type = e.currentTarget.dataset.v
    const value = e.detail
    this.setData({
      [`opt.${type}`]: value
    })

  },
  onSubmit(e) {
    /*  ApiOrderUserComment(this.data.opt).then(res => {
       if (res.code == 200) {
         wx.showToast({
           title: "评价成功",
         })
         setTimeout(() => {
           wx.reLaunch({
             url: `/pages/orderList/index?data=${'待评价'}`,
           })
         }, 1000);
       }
     }) */
    //订单评价列表
    let arr = []
    this.data.activeArr.forEach((item) => {
      if (item.value) {
        arr.push(item.name)
      }
    })
    ApiorderDoctorComment({
      ...this.data.opt,
      label: arr.toString(),
    }).then(res => {
      if (res.code == 200) {
        wx.showToast({
          title: "评价成功",
        })
        setTimeout(() => {
          wx.navigateBack()
        }, 1000);

      }
    })
  },

  onClick(e) {
    let val = e.currentTarget.dataset.v.id
    this.setData({
      ['activeArr[' + val + '].value']: !this.data.activeArr[val].value
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})